import request from '@/utils/request'
import type { 
  UserVo, 
  UserQuery, 
  UserForm, 
  ResetPasswordForm, 
  ApiKeyVo, 
  ApiKeyForm 
} from '@/types/system/user'

// 获取用户列表
export function getSystemUserList(query: UserQuery) {
  return request<{
    list: UserVo[]
    total: number
  }>({
    url: '/system/user/list',
    method: 'get',
    params: query,
  })
}

// 新增用户
export function postSystemUser(data: UserForm) {
  return request({
    url: '/system/user',
    method: 'post',
    data,
  })
}

// 修改用户
export function putSystemUser(data: UserForm) {
  return request({
    url: '/system/user',
    method: 'put',
    data,
  })
}

// 删除用户
export function deleteSystemUserId(id: string) {
  return request({
    url: `/system/user/${id}`,
    method: 'delete',
  })
}

// 重置用户密码
export function putSystemUserResetPassword(data: ResetPasswordForm) {
  return request({
    url: '/system/user/resetPassword',
    method: 'put',
    params: {
      id: data.id,
      password: data.newPassword
    },
  })
}

// 获取API Key列表
export function getApiKeyDataList(query: { loginId: string }) {
  return request<ApiKeyVo[]>({
    url: '/apiKeyData/list',
    method: 'get',
    params: query,
  })
}

// 创建API Key
export function postApiKeyDataCreate(data: ApiKeyForm) {
  return request({
    url: '/apiKeyData/create',
    method: 'post',
    data,
  })
}

// 更新API Key
export function putApiKeyDataUpdate(data: ApiKeyVo) {
  return request({
    url: '/apiKeyData/update',
    method: 'put',
    data,
  })
}

// 删除API Key
export function deleteApiKeyDataDelete(id: string) {
  return request({
    url: `/apiKeyData/delete/${id}`,
    method: 'delete',
  })
}